package com.maltys.dynamicdatasource.controller;

import com.maltys.dynamicdatasource.common.annotation.CurrentDataSource;
import com.maltys.dynamicdatasource.common.enums.DataSourceEnum;
import com.maltys.dynamicdatasource.domain.entity.User;
import com.maltys.dynamicdatasource.service.IUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
public class UserController {
    private final IUserService userService;

    @RequestMapping("/get_info")
    @CurrentDataSource(currentSource = DataSourceEnum.ACTIVE)
    public User getUserInfo(Long uid) {
        return userService.getUserInfoByUid(uid);
    }

    @RequestMapping("/get_info_back")
    @CurrentDataSource(currentSource = DataSourceEnum.BACKUP)
    public User getUserInfoBack(Long uid) {
        return userService.getUserInfoByUid(uid);
    }
}
